package com.yanqu.road.server.cmd.activity.tonbing;

import com.yanqu.road.entity.activity.tonbing.config.TonBingConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TonBingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.tonbing.TonBingMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_TON_BING_CAMP_USER_DATA,desc = "同阵营用户数据信息")
public class TonBingCampUserDataCmd extends AbstractCommand {

    private TonBingProto.TonBingCampUserDataReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = TonBingProto.TonBingCampUserDataReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        TonBingConfig config = TonBingMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }

        TonBingProto.CrossTonBingCampUserDataReqMsg.Builder builder = TonBingProto.CrossTonBingCampUserDataReqMsg.newBuilder();
        builder.setActivityId(config.getActivityInfo().getActivityId());
        builder.setCampUserDataReqMsg(reqMsg.toBuilder());
        player.sendPacket(CrossProtocol.C2_TON_BING_CAMP_USER_DATA, builder);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            TonBingProto.TonBingCampUserDataRespMsg.Builder respMsg = TonBingProto.TonBingCampUserDataRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_TON_BING_CAMP_USER_DATA, respMsg);
        }
    }
}
